# ... 文件顶部注释和之前的Lock示例保持不变 ...
import threading
import time

# Condition示例 - 生产者消费者模型
condition = threading.Condition()
items = []
MAX_ITEMS = 5

def producer():
    global items
    for i in range(10):
        with condition:
            while len(items) >= MAX_ITEMS:
                print("生产者: 缓冲区已满，等待...")
                condition.wait()
            items.append(f"产品-{i}")
            print(f"生产者: 生产了 产品-{i}")
            condition.notify()  # 通知消费者
        time.sleep(0.1)  # 模拟生产时间

def consumer():
    global items
    for _ in range(10):
        with condition:
            while not items:
                print("消费者: 缓冲区为空，等待...")
                condition.wait()
            item = items.pop(0)
            print(f"消费者: 消费了 {item}")
            condition.notify()  # 通知生产者
        time.sleep(0.2)  # 模拟消费时间

# 创建并启动线程
prod = threading.Thread(target=producer)
cons = threading.Thread(target=consumer)

prod.start()
cons.start()

prod.join()
cons.join()

print("Condition示例完成")
